#include <stdio.h>
#include <gjs/js.h>
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
#define toint(i) (i)
#define tofloat(i) (i)
void GLglutInit(void)
{
    int argc = 1;
    char *argv[] = {"gl", ""};
    glutInit(&argc, argv);
}
void GLglutCreateWindow(void *self, struct js_string *str)
{
    glutCreateWindow(str->__str);
}
void GLglutDisplayFunc(void *self, void *ptr)
{
    struct js_function *func = (struct js_function*) ptr;
    glutDisplayFunc(func->func);
}
void GLglClear(void *self, js_int_t i)
{
    glClear(toint(i));
}
void GLglBegin(void *self, js_int_t i)
{
    glBegin(i);
}
void GLglVertex2f(void *self, js_float_t f1, js_float_t f2)
{
    glVertex2f(tofloat(f1), tofloat(f2));
}
void GLglEnd(void)
{
    glEnd();
}
void GLglFlush(void)
{
    glFlush();
}
void GLglutInitDisplayMode(void *self, js_int_t i)
{
    glutInitDisplayMode(toint(i));
}
void GLglutInitWindowSize(void *self, js_int_t i1, js_int_t i2)
{
    glutInitWindowSize(toint(i1),toint(i2));
}
void GLglutInitWindowPosition(void *self, js_int_t i1, js_int_t i2)
{
    glutInitWindowPosition(toint(i1),toint(i2));
}
void GLglutMainLoop(void)
{
    glutMainLoop();
}
void GLglLoadIdentity(void)
{
    glLoadIdentity();
}
void GLglPopMatrix(void)
{
    glPopMatrix();
}
void GLglPushMatrix(void)
{
    glPushMatrix();
}
void GLglViewport(void *self, js_int_t i1, js_int_t i2, js_int_t i3, js_int_t i4)
{
    glViewport(toint(i1) ,toint(i2), toint(i3), toint(i4));
}
void GLgluPerspective(void *self, js_float_t f1, js_float_t f2, js_float_t f3, js_float_t f4)
{
    gluPerspective(tofloat(f1) ,tofloat(f2), tofloat(f3), tofloat(f4));
}
void GLgluLookAt(void *self, js_float_t f1, js_float_t f2, js_float_t f3, js_float_t f4, js_float_t f5, js_float_t f6, js_float_t f7, js_float_t f8, js_float_t f9)
{
    gluLookAt(tofloat(f1) ,tofloat(f2), tofloat(f3), tofloat(f4), tofloat(f5), tofloat(f6), tofloat(f7), tofloat(f8), tofloat(f9));
}
void GLglutPostRedisplay(void)
{
    glutPostRedisplay();
}
void GLglutSwapBuffers(void)
{
    glutSwapBuffers();
}
void GLglutWireSphere(void *self, js_float_t f1, js_float_t f2, js_float_t f3)
{
    glutWireSphere(tofloat(f1) ,tofloat(f2), tofloat(f3));
}
void GLglMatrixMode(void *self, js_int_t i)
{
    glMatrixMode(toint(i));
}
void GLglutIdleFunc(void *self, struct js_function *func)
{
    glutIdleFunc(func->func);
}
static struct js_function *ReshapeFunc;
static void __ReshapeFunc__(int w, int h)
{
    if (ReshapeFunc) {
        void (*f)(void*, int, int);
        f = (void (*)(void*, int, int) )ReshapeFunc->func;
        f(NULL, w, h);
    }
}
void GLglutReshapeFunc(void *self, struct js_function *func)
{
    ReshapeFunc = func;
    glutReshapeFunc(__ReshapeFunc__);
}
void GLglRotatef(void *self, js_float_t f1, js_float_t f2, js_float_t f3, js_float_t f4)
{
    glRotatef(tofloat(f1) ,tofloat(f2), tofloat(f3), tofloat(f4));
}
void GLglClearColor(void *self, js_float_t f1, js_float_t f2, js_float_t f3, js_float_t f4)
{
    glClearColor(tofloat(f1) ,tofloat(f2), tofloat(f3), tofloat(f4));
}
void GLglColor3f(void *self, js_float_t f1, js_float_t f2, js_float_t f3)
{
    glColor3f(tofloat(f1) ,tofloat(f2), tofloat(f3));
}
void GLglutWireTeapot(void *self, js_float_t f1, js_float_t f2)
{
    glutWireTeapot(tofloat(f1));
}
